package com.joinway.framework.admin.core.service;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;

public abstract class AbstractAdminWebService extends AbstractAdminService implements IAdminWebService {

	private final static Logger log = LoggerFactory.getLogger(AbstractAdminWebService.class);
	
	protected static final Map<String, String> METHODS = new HashMap<>();
	
	static{
		METHODS.put("profile", "Profile");
	}
	
	@Override
	public ModelAndView process(ModelAndView mv, String page) throws Exception {
		ModelAndView target = mv;
		
		String suffix = METHODS.get(page);
		
		if(StringUtils.isNotBlank(suffix)){
			String method = "process" + suffix;
			log.debug("process {} ...", method);
			MethodUtils.invokeMethod(this, method, mv);
//			this."$method"(mv);
		}
		
		return target;
	}
	
}
